package com.hdu.other.unionSet;

import java.io.*;

public class Template {

    private static final int MAX_N = 1000000;
    private static final int[] FATHER = new int[MAX_N];
    private static int N;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        StreamTokenizer st = new StreamTokenizer(br);

        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            N = (int) st.nval;
            build();
            st.nextToken();
            int m = (int) st.nval;
            while (m-- > 0) {
                st.nextToken();
                int op = (int) st.nval;
                st.nextToken();
                int x = (int) st.nval;
                st.nextToken();
                int y = (int) st.nval;
                if (op == 1) {
                    pw.println(isSameSet(x, y) ? "Yes" : "No");
                }
                else {
                    union(x, y);
                }
            }
        }

        pw.flush();
        pw.close();
        br.close();
    }

    static void build() {
        for (int i = 0; i < N; i++) {
            FATHER[i] = i;
        }
    }

    static int find(int x) {
        if (FATHER[x] != x) {
            FATHER[x] = find(FATHER[x]);
        }
        return FATHER[x];
    }

    static void union(int x, int y) {
        FATHER[find(x)] = find(y);
    }

    static boolean isSameSet(int x, int y) {
        return find(x) == find(y);
    }
}
